// 引入组件
import Vue from 'vue';
import uploadVue from './Upload.vue'

const uploadVueConstructor = Vue.extend(uploadVue);
const defaults = {
   type: 'image'
};
const uploadBox = (options = {}) => {
   options = Object.assign({}, defaults, options);
   let parent = document.body;
   let instance = new uploadVueConstructor({
      el: document.createElement('div'),
      data: options
   });
   parent.appendChild(instance.$el);
   Vue.nextTick(() => {
      instance.show = true;
      setTimeout(function () {
         instance.close();
      }, options.duration)
   });
   return instance;
};

// 定义 test 对象
const upload = {
   // install 是默认的方法。当外界在 use 这个组件的时候，
   // 就会调用本身的 install 方法，同时传一个 Vue 这个类的参数。
   install: function (Vue) {
      Vue.prototype.$upload = uploadBox;
      // Vue.component('test', uploadComponent)
   }
}

// 导出
export default upload